package trainfengxing.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import trainfengxing.pojo.HotelBooking;
import trainfengxing.pojo.Result;
import trainfengxing.service.HotelBookingService;

import java.util.List;

@Slf4j
@RestController
public class HotelBookingController {
    @Autowired
    private HotelBookingService hotelBookingService;

    @GetMapping("/bookings")
    public Result getAllBookings() {
        log.info("查询所有预订");
        List<HotelBooking> bookings = hotelBookingService.getAllBookings();
        return Result.success(bookings);
    }

    @GetMapping("/bookings/{bookingID}")
    public Result getBookingById(@PathVariable Integer bookingID) {
        log.info("查询预订详情，bookingID: {}", bookingID);
        HotelBooking booking = hotelBookingService.getBookingById(bookingID);
        return Result.success(booking);
    }

    @PostMapping("/bookings")
    public Result addBooking(@RequestBody HotelBooking booking) {
        log.info("添加新预订: {}", booking);
        hotelBookingService.addBooking(booking);
        return Result.success();
    }

    @PutMapping("/bookings")
    public Result updateBooking(@RequestBody HotelBooking booking) {
        log.info("更新预订信息: {}", booking);
        hotelBookingService.updateBooking(booking);
        return Result.success();
    }

    @DeleteMapping("/bookings/{bookingID}")
    public Result deleteBooking(@PathVariable Integer bookingID) {
        log.info("取消预订，bookingID: {}", bookingID);
        hotelBookingService.deleteBooking(bookingID);
        return Result.success();
    }

    @GetMapping("/bookings/user/{userID}")
    public Result getBookingsByUserId(@PathVariable Integer userID) {
        log.info("查询用户预订，userID: {}", userID);
        List<HotelBooking> bookings = hotelBookingService.getBookingsByUserId(userID);
        return Result.success(bookings);
    }
}